//
//  EMSCharacterSelectionTableViewCell.m
//  EVE Mac Suite
//
//  Created by Vadim Lozko on 7/14/09.
//  Copyright 2009 __MyCompanyName__. All rights reserved.
//

#import "EMSCharacterSelectionTableViewCell.h"
#import "EVECDLearnedSkill.h"
#import "EVECDLearnedGroup.h"
#import "EVECDCharacter.h"
#import "EVEAPICoreDataController.h"
#import "EMSGeneralUtils.h"
#import "EMSSkillTrainingInfo.h"

@implementation EMSCharacterSelectionTableViewCell

-(void)drawWithFrame:(NSRect)cellFrame inView:(NSView*)controlView
{
	NSDictionary* displayInfo = [self objectValue];
	if([displayInfo objectForKey:DISPLAY_INFO_DICT_CHARACTER])
	{
		EVECDCharacter* character = (EVECDCharacter*)[EVECDContext objectWithID:[displayInfo objectForKey:DISPLAY_INFO_DICT_CHARACTER]];
		NSImage* characterImage = [[NSImage alloc] initWithData:character.image];
		NSRect newRect = cellFrame;
		newRect.origin.x += 5;
		newRect.origin.y += 5;
		newRect.size.height = 40;
		newRect.size.width = 40;
		[characterImage setFlipped:YES];
		[characterImage drawInRect:newRect fromRect:NSZeroRect operation:NSCompositeCopy fraction:1.0];
		[characterImage release];

		NSColor* textColor = [self isHighlighted] ? [NSColor alternateSelectedControlTextColor] : [NSColor textColor];
		NSDictionary* regularStringAttributes = [NSDictionary dictionaryWithObjectsAndKeys:textColor, NSForegroundColorAttributeName,
												 [NSFont systemFontOfSize:10], NSFontAttributeName, nil];
		
		[character.name drawInRect:NSMakeRect(cellFrame.origin.x + 55, cellFrame.origin.y + 5, 160, 12) 
					withAttributes:regularStringAttributes];
		if([displayInfo objectForKey:DISPLAY_INFO_DICT_SKILL_IN_TRAINING_NAME])
		{
			NSString* skillName = [displayInfo objectForKey:DISPLAY_INFO_DICT_SKILL_IN_TRAINING_NAME];
			[skillName drawInRect:NSMakeRect(cellFrame.origin.x + 55, cellFrame.origin.y + 17, 160, 12) 
				   withAttributes:regularStringAttributes];
		}
		if([displayInfo objectForKey:DISPLAY_INFO_DICT_SKILL_IN_TRAINING_TIME_TO_TRAIN])
		{
			NSString* trainingTime = [displayInfo objectForKey:DISPLAY_INFO_DICT_SKILL_IN_TRAINING_TIME_TO_TRAIN];
			[trainingTime drawInRect:NSMakeRect(cellFrame.origin.x + 55, cellFrame.origin.y + 29, 160, 12) 
					  withAttributes:regularStringAttributes];
		}
	}
	
}

-(NSRect)expansionFrameWithFrame:(NSRect)cellFrame inView:(NSView*)view
{
	return NSZeroRect;
}

@end
